<div class="section">

	<div class="section-title">Quản lý bất động sản</div>
    
    <div class="section-content">
    	
        <form action="" method="post" id="listitem" name="listitem">
        	<div id="ben-search">
            	<label>Mã số</label>
                <input type="text" id="bdsid" name="bdsid" class="text" value="" />
                <label>Tiêu đề</label>
                <input type="text" id="tieude" name="tieude" class="text" value="" />
                <label>Nhu cầu</label>
                <select id="nhucau" name="nhucau">
                    <option value=""></option>
                    <?php foreach($nhucau as $val){ ?>
                    <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                    <?php } ?>
                </select>
                <label>Loại</label>
                <select id="loaibds" name="loaibds">
                    <option value=""></option>
                    <?php foreach($loaibds as $val){ ?>
                    <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                    <?php } ?>
                </select>
                <label>Hướng</label>
                <select id="huong" name="huong">
                    <option value=""></option>
                    <?php foreach($huong as $val){ ?>
                    <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                    <?php } ?>
                </select>
                <br />
                <label>Khu vực</label>
                <select id="khuvuc" name="khuvuc">
                    <option value=""></option>
                    <?php foreach($khuvuc as $val){ ?>
                    <option value="<?php echo $val['manhom']?>"><?php echo $this->string->getPrefix("&nbsp;&nbsp;&nbsp;&nbsp;",$val['level']-1)?><?php echo $val['tennhom']?></option>
                    <?php } ?>
                </select>
                <label>Giá từ</label>
                <input type="text" id="giatu" name="giatu" class="text number" value="" />
                <label>Giá đến</label>
                <input type="text" id="giaden" name="giaden" class="text number" value="" />
                <br />
                <input type="button" class="button" name="btnSearch" value="Tìm" onclick="searchForm()"/>
                <input type="button" class="button" name="btnSearch" value="Xem tất cả" onclick="window.location = '?route=addon/bds'"/>
            </div>
        	<div class="button right">
            	<?php if($dialog==true){ ?>
            	<input class="button" value="Select" type="button" onclick="selectNguyenLieu()">
                <input type="hidden" id="selectnguyenlieu" name="selectnguyenlieu" />
                <?php }else{ ?>
                
                
            	
                <?php } ?>
            </div>
            <div class="clearer">^&nbsp;</div>
            
            <div class="sitemap treeindex">
                <table class="data-table" cellpadding="0" cellspacing="0">
                <thead>
                    <tr class="tr-head">
                        <th width="1%">
                        	<?php if($dialog!=true){ ?>
                        	<input class="inputchk" type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);">
                            <?php } ?>
                        </th>
                        <th>STT</th>
                        <th>Mã bất động sản</th>
                        <th>Tiêu đề</th>
                        <th>Nhu cầu</th>
                        <th>Loai</th>
                        <th>Giá</th>
                        <th>Hướng</th>
                        <th>Khu vực</th>
                        <th>Địa chỉ</th>
                        <th>Diện tích</th>
                        <th>Hình</th>
                        <?php if($dialog!=true){ ?>
                        <th>Control</th>     
                        <?php } ?>
                    </tr>
                </thead>
                <tbody>
        
        
        <?php
            foreach($datas as $key => $item)
            {
        ?>
                    <tr>
                        <td class="check-column"><input class="inputchk" type="checkbox" name="delete[<?php echo $item['bdsid']?>]" value="<?php echo $item['bdsid']?>" ></td>
                        <td><?php echo $key+1 ?></td>
                        <td><?php echo $item['bdsid']?></td>
                        <td><?php echo $item['tieude']?></td>
                        <td><?php echo $this->document->getNhom($item['nhucau'])?></td>
                        <td><?php echo  $this->document->getNhom($item['loaibds'])?></td>
                        <td class="number"><?php echo $this->string->numberFormate($item['gia'])?></td>
                        <td><?php echo  $this->document->getNhom($item['huong'])?></td>
                        <td><?php echo  $this->document->getNhom($item['khuvuc'])?></td>
                        <td><?php echo $item['diachi']?></td>
                        <td class="number"><?php echo $this->string->numberFormate($item['dientich'])?></td>
                        <td><img src="<?php echo $item['imagethumbnail']?>" /></td>
                        <?php if($dialog!=true){ ?>
                        <td class="link-control">
                            
                            
                            <input type="button" class="button" name="btnEdit" value="Restore" onclick="restore('<?php echo $item['bdsid']?>')"/>
                        </td>
                        <?php } ?>
                    </tr>
        <?php
            }
        ?>
                        
                                                    
                </tbody>
                </table>
            </div>
        	<?php echo $pager?>
        
        </form>
        
    </div>
    
</div>
<script language="javascript">

function deleteitem()
{
	var answer = confirm("Bạn có muốn xóa không?")
	if (answer)
	{
		$.post("?route=addon/bdsdel/delete", 
				$("#listitem").serialize(), 
				function(data)
				{
					if(data!="")
					{
						alert(data)
						window.location.reload();
					}
				}
		);
	}
}

function searchForm()
{
	var url =  "?route=addon/bdsdel";
	if($("#bdsid").val() != "")
		url += "&bdsid=" + $("#bdsid").val();
	
	if($("#tieude").val() != "")
		url += "&tieude="+ $("#tieude").val();
	if($("#nhucau").val() != "")
		url += "&nhucau=" + $("#nhucau").val();
	if($("#loaibds").val() != "")
		url += "&loaibds="+ $("#loaibds").val();
	if($("#huong").val() != "")
		url += "&huong=" + $("#huong").val();
	if($("#khuvuc").val() != "")
		url += "&khuvuc=" + $("#khuvuc").val();
	if($("#giatu").val() != "")
		url += "&giatu=" + $("#giatu").val();
	if($("#giaden").val() != "")
		url += "&giaden=" + $("#giaden").val();
	
	
	if("<?php echo $_GET['opendialog']?>" == "true")
	{
		url += "&opendialog=true";
	}
	
	window.location = url;
}

$("#bdsid").val("<?php echo $_GET['bdsid']?>");
$("#tieude").val("<?php echo $_GET['tieude']?>");
$("#nhucau").val("<?php echo $_GET['nhucau']?>");
$("#loaibds").val("<?php echo $_GET['loaibds']?>");
$("#huong").val("<?php echo $_GET['huong']?>");
$("#khuvuc").val("<?php echo $_GET['khuvuc']?>");
$("#giatu").val("<?php echo $_GET['giatu']?>");
$("#giaden").val("<?php echo $_GET['giaden']?>");

function selectBatDongSan()
{
	window.opener.document.getElementById('manguyenlieu').value = $("#selectnguyenlieu").val();
	window.close();
}

<?php if($dialog==true){ ?>
	$(".inputchk").click(function()
	{
		$("#selectnguyenlieu").val('');
		$(".inputchk").each(function(){
			if(this.checked == true)
			{
				$("#selectnguyenlieu").val($("#selectnguyenlieu").val()+","+$(this).val());
			}
		})
		
	});
<?php } ?>

function restore(bdsid)
{
	$.get("?route=addon/bdsdel/restore&bdsid="+bdsid, 
			
			function(data)
			{
				if(data=="true")
				{
					
					window.location.reload();
				}
			}
	);
}

</script>